package com.alibaba.citrus.ots.platform.enhance.functions.diff.sap.dataParser;

import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.constant.SalesOrderDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.dataParser.DataParser;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.common.FieldLineDTO;
import com.alibaba.cz.base.tool.log.Log;
import com.epoch.app.otsapplicationadaptersdk.sap.MnSapIf015SDO;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hanguo
 * @date 2022/1/23
 * @Description SapIf015SDO数据解析
 */
@Component
public class SapIf015SDODataParse extends DataParser {

    /**
     * 日志
     */
    private static Log log = Log.getLogger(SapIf015SDODataParse.class);

    /**
     * 数据库字段，映射成对账处理的业务字段(标准字段)
     * key：数据库中的字段，value：转换后的字段,这里的 value 字段也不要重复
     */
    private static Map<String, String> dataBaseFiledMapping = new HashedMap();

    static {
        dataBaseFiledMapping.put("tradeOrderId", SalesOrderDiffStandardFieldDict.OTS_SALES_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("outOrderId",SalesOrderDiffStandardFieldDict.SAP_SALES_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("orderType",SalesOrderDiffStandardFieldDict.ORDER_TYPE.getFieldCode());
        dataBaseFiledMapping.put("saleOrganizationCode",SalesOrderDiffStandardFieldDict.SALE_ORGANIZATION_CODE.getFieldCode());
        dataBaseFiledMapping.put("sapChannel",SalesOrderDiffStandardFieldDict.CHANNEL_CODE.getFieldCode());
        dataBaseFiledMapping.put("productGroupCode",SalesOrderDiffStandardFieldDict.PRODUCT_GROUP_CODE.getFieldCode());
        dataBaseFiledMapping.put("saleChannelCode",SalesOrderDiffStandardFieldDict.SALE_CHANNEL_CODE.getFieldCode());
        dataBaseFiledMapping.put("saleDepartmentCode",SalesOrderDiffStandardFieldDict.SALE_DEPARTMENT_CODE.getFieldCode());
        dataBaseFiledMapping.put("soldPartCode",SalesOrderDiffStandardFieldDict.CUSTOMER_CODE.getFieldCode());
        dataBaseFiledMapping.put("deliveryPartCode",SalesOrderDiffStandardFieldDict.RECEIVE_ADDRESS_CODE.getFieldCode());
        //dataBaseFiledMapping.put("cashCustomerName",SalesOrderDiffStandardFieldDict.CASH_CUSTOMER_NAME.getFieldCode());
        dataBaseFiledMapping.put("createReason",SalesOrderDiffStandardFieldDict.CREATE_REASON.getFieldCode());
        dataBaseFiledMapping.put("shipType",SalesOrderDiffStandardFieldDict.TRANSPORT_MODE_CODE.getFieldCode());
        dataBaseFiledMapping.put("factoryCode",SalesOrderDiffStandardFieldDict.FACTORY_CODE.getFieldCode());
        dataBaseFiledMapping.put("inventoryCode",SalesOrderDiffStandardFieldDict.INVENTORY_CODE.getFieldCode());
        dataBaseFiledMapping.put("costCenter",SalesOrderDiffStandardFieldDict.COST_CENTER.getFieldCode());

    }


    @Override
    public Map<String, FieldLineDTO> parse(Object obj) {
        Map<String, FieldLineDTO> map = new HashMap<>();
        if (obj instanceof MnSapIf015SDO) {
            MnSapIf015SDO mnSapIf015SDO = (MnSapIf015SDO) obj;
            return obtainFieldLineMap(dataBaseFiledMapping, mnSapIf015SDO, mnSapIf015SDO.getClass());
        }
        return map;
    }

    @Override
    public String obtainProcessType() {
        return "MnSapIf015SDO";
    }
}
